/*
 * @author: huangww
 * @Date: 2021-02-26 10:51:05
 * @LastEditTime: 2021-03-01 11:19:49
 * @FilePath: \fmgr\src\core\res\LoadGroup.ts
 */
namespace core {
  export class LoadGroup {
    groups: Array<string>;
    retains: Array<string>;
    count: number = 0;
    parseList: Array<DbParse> = [];

    constructor(groups: Array<string> = null, retains: Array<string> = null) {
      this.groups = groups;
      this.retains = retains;
      if (this.groups && this.groups.length > 0) {
        this.count = this.groups.length;
      }

    }

    retain(retain = true) {
      if (retain) {
        this.retains = [];
        for (let i of this.groups) {
          this.retains.push(i);
        }
      } else {
        this.retains = null;
      }
    }

    //追加资源组
    append(names: string | LoadGroup) {
      let group: LoadGroup = this;
      if (typeof (names) == "string") {
        this.groups.push(names);
      } else {
        this.groups = this.groups.concat(names.groups);
        this.retains = this.retains.concat(names.retains);
        this.count = this.count + names.count;
        this.parseList = this.parseList.concat(names.parseList);
      }
    }

    isRetain(name: string): boolean {
      if (!this.retains || this.retains.length === 0) return false;
      for (let i of this.retains) {
        if (i === name) {
          return true;
        }
      }
      return false;
    }

    //设置龙骨资源解析表
    setDBParseList(parseList: Array<DbParse>, hdParseList: Array<DbParse> = null) {
      if (hdParseList) {
        parseList = parseList.concat(hdParseList);
      }
      this.parseList = parseList;
    }

    addDBParseList(parseArr: Array<string>, count = 1, retain = true) {
      for (let i of parseArr) {
        let item = new DbParse(i, count, retain);
        this.parseList.push(item);
      }
    }
  }

}